package com.example.schooljava.controller;

import com.example.schooljava.annotation.RequestLimit;
import com.example.schooljava.pojo.dto.AddClassCurrDTO;
import com.example.schooljava.pojo.dto.ClassCurrDTO;
import com.example.schooljava.pojo.bo.AddClassCurrBO;
import com.example.schooljava.pojo.bo.ClassCurrBO;
import com.example.schooljava.service.impl.ClassCurrServiceImpl;
import com.example.schooljava.util.DTOtoBO;
import com.example.schooljava.util.Result;
import com.example.schooljava.util.ValidationGroups;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * 功能描述
 *
 * @author: LDH
 * @date: 2022年08月26日 17:50
 */
@RestController
@RequestMapping("/school/class-curr")
@RequestLimit(maxCount = 5,second = 2)
@Api(tags = "班级课程关系模块")
public class ClassCurrController {

    @Autowired
    private ClassCurrServiceImpl classCurrService;
    @Autowired
    private DTOtoBO dtOtoBO;

    @ApiOperation(value = "获取班级课程名",notes = "<span style='color:red;'>详细描述：</span>&nbsp; 根据当前班级id，获取该班级的课程信息")
    @GetMapping( name = "校长,班主任")
    public Result getCurrOfClass(@RequestParam String classid){
        Long id = Long.parseLong(classid);
        return classCurrService.getCurrOfClass(id);
    }

    @ApiOperation(value = "为班级添加课程",notes = "<span style='color:red;'>详细描述：</span>&nbsp;学校管理人员建立某班级和某课程的关系")
    @PostMapping(value = "/add", name = "校长")
    public Result addClassCurr(@RequestBody @Validated(ValidationGroups.Add.class) AddClassCurrDTO addClassCurrDTO){
        AddClassCurrBO addClassCurrBO = new AddClassCurrBO();
        return classCurrService.addClassCurr((AddClassCurrBO) dtOtoBO.copyPro(addClassCurrDTO,addClassCurrBO));
    }

    @ApiOperation(value = "获取课程班级教师关系",notes = "<span style='color:red;'>详细描述：</span>&nbsp;学校管理员人获取班级和课程和教师的关系信息")
    @PostMapping(value = "/class-curr", name = "校长")
    public Result getRelation(@RequestBody ClassCurrDTO classCurrDTO){
        // 去除课程名前后空格
        classCurrDTO.setCurriculum(classCurrDTO.getCurriculum().trim());
        ClassCurrBO classCurrBO = new ClassCurrBO();
        return classCurrService.getRelation((ClassCurrBO) dtOtoBO.copyPro(classCurrDTO,classCurrBO));
    }

    @ApiOperation(value = "获取所有班级",notes = "<span style='color:red;'>详细描述：</span>&nbsp;获取某个年级下的所有班级")
    @GetMapping(value = "/classname", name = "校长")
    public Result getClassName(@RequestParam Integer grade){
        return classCurrService.getClassName(grade);
    }

    @ApiOperation(value = "获取课程",notes = "<span style='color:red;'>详细描述：</span>&nbsp; 获取某个年级下的所有课程")
    @GetMapping(value = "/curr", name = "校长")
    public Result getCurrOfGrade(@RequestParam Integer grade){
        return classCurrService.getCurrOfGrade(grade);
    }

    @ApiOperation(value = "删除班级",notes = "<span style='color:red;'>详细描述：</span>&nbsp;批量删除班级课程关系")
    @DeleteMapping(value = "/del", name = "校长")
    public Result delClassCurr(ArrayList<String> list){
        return classCurrService.delClassCurr(list);
    }

    @ApiOperation(value = "修改班级关系信息",notes = "<span style='color:red;'>详细描述：</span>&nbsp;学校管理员修改班级课程关系信息")
    @PutMapping(value = "/edit", name = "校长")
    public Result editClassCurr(@RequestBody @Validated(ValidationGroups.Update.class) AddClassCurrDTO addClassCurrDTO){
        AddClassCurrBO addClassCurrBO = new AddClassCurrBO();
        return classCurrService.editClassCurr((AddClassCurrBO) dtOtoBO.copyPro(addClassCurrDTO,addClassCurrBO));
    }

    @ApiOperation(value = "获取年级",notes = "<span style='color:red;'>详细描述：</span>&nbsp;获取已存在的所有年级")
    @GetMapping(value = "/grade", name = "校长")
    public Result getGrade(){
        return classCurrService.getGrade();
    }

    @ApiOperation(value = "获取教师",notes = "<span style='color:red;'>详细描述：</span>&nbsp;获取有教指定课程的或没有教课的教师")
    @GetMapping(value = "/teacher", name = "校长")
    public Result getTeacherOfCurr(String curriculum){
        return classCurrService.getTeacherOfCurr(curriculum);
    }
}